import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Admin } from './admin.entity';

@Injectable()
export class AdminService {
    constructor(
        @InjectRepository(Admin)
        private adminRepository: Repository<Admin>,
    ) { }

    async findAll(): Promise<Admin[]> {
        return await this.adminRepository.find();
    }

    async findByUserNameAndPassword(username: string, password: string): Promise<Admin> {
        return await this.adminRepository.createQueryBuilder("admin")
            .where("admin.username = :username", { username: username, password: password })
            .getOne();
    }

    async findByUserName(username: string) {
        return await this.adminRepository.createQueryBuilder("admin")
            .where("admin.username = :username", {username: username})
            .getOne();
    }

}
